package com.kangye.enterprise.frontdesk.controller;

import com.kangye.enterprise.frontdesk.entity.Users;
import com.kangye.enterprise.frontdesk.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @program: enterprise
 * @description: 用户Controller
 * @author: 索腾龙
 * @create: 2021-05-26 10:14
 **/
@RestController
@CrossOrigin
@Configuration
@RequestMapping("/users")
public class UsersController {
    @Autowired
    private UsersService usersService;
    //用户app登录(索腾龙)
    @RequestMapping("/login")
    public String login(HttpSession httpSession, String usersUserName, String usersPassword){
        //用实体类User去接收sqlsession里的数据库操作方法
        Users users = usersService.Login(usersUserName);
        if (users!=null){
            //判断输入的密码是否等于数据库的密码  如果相等
            if (users.getUsersPassword().equals(usersPassword)){
                //将获取的信息存入session里
                httpSession.setAttribute("users",users);
                //跳首页
                return "200";
            }else {
                //失败
                return "201";
            }
        }else {
            return "201";
        }
    }
    @RequestMapping("/logins")
    public String logins(HttpSession session){
        Users users = (Users) session.getAttribute("users");
        System.out.println(users);
        return "查询结果"+users;
    }
}